package cn.eports.learn.web.servlet;

import cn.eports.learn.domain.User;
import cn.eports.learn.service.UserService;
import cn.eports.learn.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/findUserServlet")
public class FindUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        super.doGet(req, resp);
        // 1. 获取id
        final String id = req.getParameter("id");

        // 2. 使用service服务查找
        final UserService service = new UserServiceImpl();
        User user = service.findUserById(id);

        //3.将user存入request
        req.setAttribute("user",user);

        // 4. 跳转到update.jsp
        req.getRequestDispatcher("/update.jsp").forward(req, resp);


    }


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
